package cn.desk.user.action;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.desk.commons.action.CurdAction;
import cn.desk.commons.entity.PageMode;
import cn.desk.commons.exception.DeskException;
import cn.desk.user.entity.User;

public class UserAction<T extends User> extends CurdAction<T> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public static final String SESSION_KEY_USER = "USER_SESSION_KEY";
	private static final Logger LOGGER = LoggerFactory
			.getLogger(UserAction.class);

	public String login() {
		try {
			LOGGER.debug("login start");
			T temp = service.load(t);
			if (!temp.getPassword().equals(t.getPassword())) {
				throw new DeskException("", t);
			}
			setSession(SESSION_KEY_USER, temp);
			return "login";
		} catch (DeskException e) {
			throw new DeskException("EMUM0003");
		} finally {
			LOGGER.debug("login end");
		}
	}

	@Override
	public String listPage() {
		return super.listPage();
	}

	@Override
	public String getModeName() {
		return "user";
	}

	@Override
	public Map<String, List<String>> getFieldErrors() {
		return super.getFieldErrors();
	}

	@Override
	public Collection<String> getActionErrors() {
		return super.getActionErrors();
	}

	@Override
	public T getT() {
		return super.getT();
	}

	@Override
	public PageMode<T> getPageMode() {
		return super.getPageMode();
	}
}
